import * as types from '../types'
import api from '../../fetch/api'
import reg from '../../fetch/reg'

const state = {
	token: "", //首页banner
	indexdata:{},//首页内容
	LabelInput: {},
	ListNavData: {},
	
	ScenicText: "",
	page: "",
	citylist: "",
	AllProvince: {}, // 注册时获取全部省份
	AllCity: {}, //注册时获取全部市/县
	Alldistrict: {},
	SidebarNavIndex: "", //系统设置选中项
	headerIndex: "", //头部选中项
	navItems:[false,false,false,false,false,false],
	}
const actions = {
	setToken({
		dispatch,
		commit
	}, res) {
		commit(types.COM_TOKEN, res)
	},
	getindexdata({
		dispatch,
		commit
	}, res) {
		commit(types.COM_INDEX_DATA, res)
		},
	setLabelInput({
		dispatch,
		commit
	}, res) {
		commit(types.COM_LABELINPUT, res)
	},
	setListNavData({
		dispatch,
		commit
	}, res) {
		commit(types.COM_LISTNAV_DATA, res)
	},
	setScenicText({
		dispatch,
		commit
	}, res) {
		commit(types.COM_SCENICTEXT, res)
	},
	setcitylist({
		dispatch,
		commit
	}, res) {
		commit(types.COM_CITYLITt_DATA, res)
	},
	getAllProvince({
		dispatch,
		commit
	}, res) {
		api.GetAllProvince(res).then(res => {
			if (res.code === 200)
				commit(types.COM_AllPROVINCE_DATA, res.result)
		})
	},
	getAllCity({
		dispatch,
		commit
	}, res) {
		api.GetAllCity(res.data).then(result => {
			if (result.code === 200) {
				if (res.type === "prov") {
					commit(types.COM_AllCITY_DATA, result.result)
				} else if (res.type === "city") {
					commit(types.COM_AllDISTRICT_DATA, result.result)
				} else {
					commit(types.COM_AllCITY_DATA, {})
					commit(types.COM_AllDISTRICT_DATA, {})
				}
			}
		})
	},
	getpage({
		dispatch,
		commit
	}, res) {
		commit(types.COM_PAGE, res)
	},
	getSidebarNavIndex({
		dispatch,
		commit
	}, res) {
		commit(types.COM_SIDEBARNAV_INDEX, res)
	},
	getheaderIndex({
		dispatch,
		commit
	}, res) {
		commit(types.COM_HEADER_INDEX, res)
	},
	
	setNavItems({ dispatch, commit }, res) {
		commit(types.COM_NAVITEMS,res)
	},
}

const getters = {
	token: state => state.token, //首页banner
	indexdata: state => state.indexdata, //输入框数据
	LabelInput: state => state.LabelInput, //输入框数据
	ListNavData: state => state.ListNavData, //输入框数据
	citylist: state => state.citylist, //入住获取城市编码
	AllProvince: state => state.AllProvince, //注册时获取全部省份
	AllCity: state => state.AllCity, //注册时获取全部市/县
	Alldistrict: state => state.Alldistrict, //注册时获取全部市/县
	ScenicText: state => state.ScenicText, //富文本框
	page: state => state.page, //注册时获取全部市/县
	SidebarNavIndex: state => state.SidebarNavIndex, //注册时获取全部市/县
	headerIndex: state => state.headerIndex, //注册时获取全部市/县
	navItems: state => state.navItems, 

}
const mutations = {
	[types.COM_TOKEN](state, res) {
		state.token = res
	},
	[types.COM_INDEX_DATA](state, res) {
		state.indexdata = res
	},
	[types.COM_LABELINPUT](state, res) {
		state.LabelInput = res
	},
	[types.COM_LISTNAV_DATA](state, res) {
		state.ListNavData = res
	},
	[types.COM_CITYLITt_DATA](state, res) {
		state.citylist = res
	},
	[types.COM_AllPROVINCE_DATA](state, res) {
		state.AllProvince = res
	},
	[types.COM_AllCITY_DATA](state, res) {
		state.AllCity = res
	},
	[types.COM_AllDISTRICT_DATA](state, res) {
		state.Alldistrict = res
	},
	[types.COM_SCENICTEXT](state, res) {
		state.ScenicText = res
	},
	[types.COM_PAGE](state, res) {
		state.page = res
	},
	[types.COM_SIDEBARNAV_INDEX](state, res) {
		state.SidebarNavIndex = res
	},
	[types.COM_HEADER_INDEX](state, res) {
		state.headerIndex = res
	},
	
	[types.COM_NAVITEMS](state, res) {
		state.navItems = res
	},
}

export default {
	state,
	actions,
	getters,
	mutations
}
